home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / util / faxanswer.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  95 lines

  1. /*    $Header: /usr/people/sam/fax/util/RCS/faxanswer.c,v 1.16 1994/02/28 14:24:28 sam Rel $
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <syslog.h>
  28. #include <stdarg.h>
  29. #include <errno.h>
  30. #include <fcntl.h>
  31. #include <stdlib.h>
  32. #include <unistd.h>
  33.  
  34. #include "config.h"
  35. #include "port.h"
  36.  
  37. static void
  38. fatal(char* fmt, ...)
  39. {
  40.     va_list ap;
  41.     va_start(ap, fmt);
  42.     if (isatty(fileno(stderr))) {
  43.     vfprintf(stderr, fmt, ap);
  44.     putc('\n', stderr);
  45.     } else
  46.     vsyslog(LOG_ERR, fmt, ap);
  47.     va_end(ap);
  48.     exit(-1);
  49. }
  50.  
  51. void
  52. main(int argc, char** argv)
  53. {
  54.     extern int optind;
  55.     extern char* optarg;
  56.     int fifo, c;
  57.     char* spooldir = FAX_SPOOLDIR;
  58.     char* how = "";
  59.     char fifoname[256];
  60.     char answercmd[80];
  61.  
  62.     openlog(argv[0], LOG_PID, LOG_FAX);
  63.     while ((c = getopt(argc, argv, "h:q")) != -1)
  64.     switch (c) {
  65.     case 'h':
  66.         how = optarg;
  67.         break;
  68.     case 'q':
  69.         spooldir = optarg;
  70.         break;
  71.     case '?':
  72.         fatal("Bad option `%c'; usage: %s [-h how] [-q queue-dir] [modem]",
  73.         c, argv[0]);
  74.         /*NOTREACHED*/
  75.     }
  76.     if (optind == argc-1) {
  77.     if (argv[optind][0] == FAX_FIFO[0])
  78.         strcpy(fifoname, argv[optind]);
  79.     else
  80.         sprintf(fifoname, "%s.%.*s", FAX_FIFO,
  81.         sizeof (fifoname) - sizeof (FAX_FIFO), argv[optind]);
  82.     } else
  83.     strcpy(fifoname, FAX_FIFO);
  84.     if (chdir(spooldir) < 0)
  85.     fatal("%s: chdir: %s", spooldir, strerror(errno));
  86.     fifo = open(fifoname, O_WRONLY|O_NDELAY);
  87.     if (fifo < 0)
  88.     fatal("%s: open: %s", fifoname, strerror(errno));
  89.     sprintf(answercmd, "A%s", how);
  90.     if (write(fifo, answercmd, strlen(answercmd)) != strlen(answercmd))
  91.     fatal("FIFO write failed for answer (%s)", strerror(errno));
  92.     (void) close(fifo);
  93.     exit(0);
  94. }
  95.